package com.zian.service.impl;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zian.domain.dto.PageDTO;
import com.zian.domain.po.SysOperLog;
import com.zian.domain.query.PageQuery;
import com.zian.mapper.SysOperLogMapper;
import com.zian.service.ISysOperLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 操作日志记录 服务实现类
 * </p>
 *
 * @author
 * @since 2024-10-23
 */
@Service
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements ISysOperLogService {

    /**
     * 新增操作日志
     *
     * @param sysOperLog
     */
    @Override
    public void insertOperlog(SysOperLog sysOperLog) {
        if (sysOperLog == null) return;
        save(sysOperLog);
    }

    @Override
    public PageDTO<SysOperLog> queryPage(PageQuery query) {
        Page<SysOperLog> page = query.toMpPage(new OrderItem("oper_time", false));
        lambdaQuery()
                .page(page);
        if (page.getRecords().isEmpty()) return PageDTO.empty(0L, 0L);
        return PageDTO.of(page);
    }
}
